package cn.element.io.convert;

import java.io.*;

public class ConvertStream {

    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;

        //通过转换流进行转换,实质上就是适配器模式
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out));

            while (true) {
                bw.write("请输入: ");
                bw.newLine();
                bw.flush();

                String input = br.readLine();  //通过键盘输入获取内容

                if ("exit".equals(input)) {
                    break;
                }

                bw.write("您输入的是: ");
                bw.write(input);
                bw.newLine();
                bw.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
